package com.jieshuibao.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jieshuibao.common.config.Const;
import com.jieshuibao.common.config.enumtype.QuestionStatus;
import com.jieshuibao.common.res.BaseRes;
import com.jieshuibao.model.db.Answer;
import com.jieshuibao.model.db.AnswerUser;
import com.jieshuibao.model.db.Counselor;
import com.jieshuibao.model.db.Duty;
import com.jieshuibao.model.db.Praise;
import com.jieshuibao.model.db.PraiseExample;
import com.jieshuibao.model.db.PraiseExample.Criteria;
import com.jieshuibao.model.db.Question;
import com.jieshuibao.model.db.QuestionUserEx;
import com.jieshuibao.model.db.QuestionUserKey;
import com.jieshuibao.model.db.Secretly;
import com.jieshuibao.model.db.User;
import com.jieshuibao.model.db.UserDealRecord;
import com.jieshuibao.model.domain.AddAdmireResponse;
import com.jieshuibao.model.domain.AnswerUserRequest;
import com.jieshuibao.model.domain.AnswerUserResponse;
import com.jieshuibao.model.domain.ApproveOpposeRequest;
import com.jieshuibao.model.domain.CookieUser;
import com.jieshuibao.model.domain.OpenQuestionRequest;
import com.jieshuibao.model.domain.PageRequest;
import com.jieshuibao.model.domain.QuestionAdmireResponse;
import com.jieshuibao.model.domain.ScoreRequest;
import com.jieshuibao.model.domain.UpdateAnswerStatusRequest;
import com.jieshuibao.model.domain.UpdateAnswerStatusResponse;
import com.jieshuibao.service.AnswerService;
import com.jieshuibao.service.AnswerUserService;
import com.jieshuibao.service.CounselorDutyService;
import com.jieshuibao.service.DiscussService;
import com.jieshuibao.service.DiscussUserService;
import com.jieshuibao.service.IntegralService;
import com.jieshuibao.service.PayVipBanlanceService;
import com.jieshuibao.service.PraiseService;
import com.jieshuibao.service.PushService;
import com.jieshuibao.service.QuestionExService;
import com.jieshuibao.service.QuestionService;
import com.jieshuibao.service.QuestionUserService;
import com.jieshuibao.service.RedisService;
import com.jieshuibao.service.SecretlyService;
import com.jieshuibao.service.SensitivewordFilterService;
import com.jieshuibao.service.SmsSendService;
import com.jieshuibao.service.UserService;
import com.jieshuibao.service.WeiXinPayService;
import com.jieshuibao.util.DateUtils;
import com.jieshuibao.util.IdGen;
import com.jieshuibao.util.MoneyRandom;
import com.jieshuibao.util.NetworkUtil;
import com.jieshuibao.util.PayTypeUtil;
import com.jieshuibao.util.StringUtils;
import com.jieshuibao.util.UUIDGenerator;
import com.jieshuibao.util.push.PushType;
import com.jieshuibao.wx.po.WxAppPayReq;
import com.jieshuibao.wx.po.WxAppPayRes;
import com.jieshuibao.wx.po.WxJsPayReq;
import com.jieshuibao.wx.po.WxjsPayRes;
import com.jieshuibao.wx.util.PayCommonUtil;

@Controller
@RequestMapping(value = "/answer")
public class AnswerController {

	private static final Logger logger = LoggerFactory
			.getLogger("AnswerController.class");

	private static final ObjectMapper mapper = new ObjectMapper();

	private static final String appId = "8aaf07086619653001661b1865b301fa";
	@Resource
	private RedisService redisService;

	@Resource
	private AnswerService answerService;

	@Resource
	private QuestionService questionService;

	@Resource
	private UserService userService;

	@Resource
	private AnswerUserService answerUserService;

	@Resource
	private DiscussService discussService;

	@Resource
	private DiscussUserService discussUserService;

	@Resource
	private QuestionUserService questionUserService;

	@Resource
	private WeiXinPayService weiXinPayService;

	@Resource
	private PayVipBanlanceService payVipBanlanceService;

	@Resource
	private CounselorDutyService counselorDutyService;

	@Resource
	private QuestionExService questionExService;

	@Resource
	private SecretlyService secretlyService;

	@Resource
	private SmsSendService smsSendService;

	@Resource
	private PushService pushService;

	@Resource
	private SensitivewordFilterService SensitivewordFilterService;

	@Resource
	private IntegralService IntegralService;

	@Resource
	private PraiseService praiseService;

	@Value("${producttype.ttk}")
	private String producttypeTtk;

	@Value("${producttype.xs}")
	private String producttypeXs;

	@Value("${price.num}")
	private int priceNum;

	// 揭榜提交接口
	@RequestMapping(value = "/openQuestion", method = RequestMethod.POST)
	@ResponseBody
	public Object openQuestionTwo(HttpServletRequest request,
			@RequestBody OpenQuestionRequest openQuestionRequest) {
		QuestionAdmireResponse questionAdmireResponse = new QuestionAdmireResponse();
		try {
			logger.info("接收：" + mapper.writeValueAsString(openQuestionRequest));
			String cookieId = request.getHeader("cookieId");
			if (cookieId != null) {
				// String phoneNum = redisService.get(cookieId);
				CookieUser cookieUser = (CookieUser) request
						.getAttribute("cookieUser");

				if (cookieUser != null) {
					String phoneNum = cookieUser.getPhoneNumber();
					if (phoneNum != null) {
						String answerContent = openQuestionRequest
								.getAnswerContent();
						String questionUuid = openQuestionRequest
								.getQuestionUuid();
						String taxId = openQuestionRequest.getTaxId();
						String topicId = openQuestionRequest.getTopicId();
						if (StringUtils.isBlank(topicId)
								|| StringUtils.isBlank(taxId)) {
							questionAdmireResponse
									.setCode(BaseRes.ERRORPARAM_CODE);
							questionAdmireResponse.setDes("请更新版本！");
							return questionAdmireResponse;
						}
						Question questionByUuid = questionService
								.getQuestionByUuid(questionUuid);
						User user = userService.getUserByPhoneNumber(phoneNum);
						if (user != null) {
							String realName = user.getRealName();
							if (realName != null && !realName.equals("")) {
								Integer role = user.getRole();
								if (role == 2) {
									if (questionByUuid != null
											&& answerContent != null
											&& !answerContent.equals("")) {
										Answer answer = answerUserService
												.getAnswerStatus(questionUuid,
														phoneNum);
										if (answer != null) {
											Integer status = answer.getStatus();
											if (status == 0) {
												answer.setContent(answerContent);
												answer.setStatus(1);
												answer.setDate(new Date());
												answer.setTax(taxId);
												answer.setTopic(topicId);
												Question question = new Question();
												question.setUuid(questionUuid);
												/*
												 * String[] split = null; if
												 * (StringUtils
												 * .isNotBlank(answerUserPhones
												 * )) {
												 * question.setAnswerUserPhones
												 * (answerUserPhones + "," +
												 * phoneNum); split =
												 * answerUserPhones .split(",");
												 * } else {
												 * question.setAnswerUserPhones
												 * (phoneNum); }
												 */

												question.setAnswerUserPhones(phoneNum);
												question.setTax(taxId);
												question.setTopic(topicId);
                                                Integer status2 = questionByUuid.getStatus();
                                                if (status2==null||status2==QuestionStatus.QU_STATUS_CHUSHI.getCode()) {
                                                    question.setStatus(QuestionStatus.QU_STATUS_ANSWER.getCode());
                                                }

												answerUserService
														.updateAnswerAndQuestion(
																answer,
																question);
												questionAdmireResponse
														.setCode(BaseRes.SUCCESS_CODE);
												questionAdmireResponse
														.setDes("提交成功");
												Integer answerNum = questionByUuid
														.getAnswerNum();
												// String[] split =
												// answerUserPhones.split(",");
												String phoneNum2 = questionByUuid
														.getPhoneNum();
												User user2 = userService
														.getUserByPhoneNumber(phoneNum2);
												String[] str1 = { questionUuid,questionByUuid.getContent()};
												if (answerNum == 2) {
													// 已有三条答案
													if (user2 != null) {
														String phone = user2
																.getPhone();

														//String name = phone;
														String realName2 = user2
																.getRealName();
														if (realName2 != null
																&& !realName2
																		.equals("")) {
															//name = realName2;
														}

														smsSendService
																.sendNotify(
																		appId,
																		phone,
																		Const.SCENE_QUESTION_ANSWER,
																		new String[]{questionByUuid.getContent()});

														// pushService.sendAndroidCustomizedcast(
														// BaseRes.RELOGIN_CODE,str,phone,
														// BaseRes.SUCCESS_CODE);
														// pushService.sendIOSCustomizedcast(
														// BaseRes.RELOGIN_CODE,str,phone);

														pushService
																.pushAlias(
																		PushType.MODEL_7,
																		str1,
																		phoneNum2,
																		"1");
													}
												} else {
													pushService.pushAlias(
															PushType.MODEL_7,
															str1, phoneNum2,
															"1");
													smsSendService
													.sendNotify(
															appId,
															user2.getPhone(),
															Const.SCENE_QUESTION_ANSWER,
															new String[]{questionByUuid.getContent()});
												}

											} else {
												// 数据格式错诶
												questionAdmireResponse
														.setCode(BaseRes.ERRORPARAM_CODE);
												questionAdmireResponse
														.setDes("已回答过！");
											}
										} else {
											//
											questionAdmireResponse
													.setCode(BaseRes.ERRORPARAM_CODE);
											questionAdmireResponse
													.setDes("数据格式错误！");
										}
									} else {
										// 答案不能为空
										questionAdmireResponse
												.setCode(BaseRes.ERRORPARAM_CODE);
										questionAdmireResponse
												.setDes("答案不能为空！");
									}
								} else {
									// 你不是咨询师
									questionAdmireResponse.setCode("4");
									questionAdmireResponse.setDes("你不是咨询师！");
								}
							} else {
								// 未完善信息
								questionAdmireResponse.setCode("4");
								questionAdmireResponse.setDes("未完善信息");
							}
						} else {
							// 数据格式错误
							questionAdmireResponse
									.setCode(BaseRes.ERRORPARAM_CODE);
							questionAdmireResponse.setDes("数据格式错误！");
						}

					} else {
						// 未登录 登陆时间过期
						questionAdmireResponse.setCode(BaseRes.RELOGIN_CODE);
						questionAdmireResponse.setDes("请重新登录");
					}
				} else {
					// 未登录
					questionAdmireResponse.setCode(BaseRes.RELOGIN_CODE);
					questionAdmireResponse.setDes("请重新登录");
				}

			} else {
				// 未登录
				questionAdmireResponse.setCode(BaseRes.RELOGIN_CODE);
				questionAdmireResponse.setDes("请重新登录");
			}
			logger.info("返回："
					+ mapper.writeValueAsString(questionAdmireResponse));
		} catch (Exception e) {
			e.printStackTrace();
			questionAdmireResponse.setCode("0");
			questionAdmireResponse.setDes("系统繁忙请稍后再试！");
		}

		return questionAdmireResponse;
	}

	// 修改答案的状态 举报 采纳
	/**
	 * 
	 * @param request
	 * @param updateAnswerStatusRequest
	 * @return
	 */
	@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
	@ResponseBody
	public Object updateAnswerStatus(HttpServletRequest request,
			@RequestBody UpdateAnswerStatusRequest updateAnswerStatusRequest) {
		UpdateAnswerStatusResponse updateAnswerStatusResponse = new UpdateAnswerStatusResponse();
		try {
			logger.info("接收："
					+ mapper.writeValueAsString(updateAnswerStatusRequest));

			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			String phoneNum = cookieUser.getPhoneNumber();
			String answerUuid = updateAnswerStatusRequest.getAnswerUuid();
			Answer answerByUuid = answerService.getAnswerByUuid(answerUuid);
			if (answerByUuid != null) {
				Integer status2 = answerByUuid.getStatus();
				String questionUuid = answerByUuid.getQuestionUuid();
				String phoneNumber = answerByUuid.getPhoneNumber();
				if (status2 == 1||status2 == 5) {
					Answer answer = new Answer();
					int status = updateAnswerStatusRequest.getStatus();
					if (status == 2 || status == 4) {
						Question question = questionService
								.getQuestionByUuid(questionUuid);
						User user = userService
								.getUserByPhoneNumber(phoneNumber);
						if (question != null && user != null) {
							String phone = user.getPhone();

							Integer status3 = question.getStatus();
							if (status3 == 1 || status3 == 2) {
								// User user2 = new User();
								Integer money1 = question.getMoney();
								Integer addMoney = question.getAddMoney();
								int money = money1 + addMoney;
								// double subMoney =
								// MoneyRandom.getSubMoney(money);

								Question question2 = new Question();
								question2.setPayType(question.getPayType());
								question2.setTax(answerByUuid.getTax());
								question2.setTopic(answerByUuid.getTopic());

								answer.setStatus(2);
								answer.setScore(5);
								answer.setAppraisal("暂无评价内容");
								answer.setUuid(answerUuid);
								answer.setPhoneNumber(phoneNumber);

								updateAnswerStatusResponse
										.setCode(BaseRes.SUCCESS_CODE);
								// 采纳过后把钱分给回答者
								String counselorUuid = user.getCounselorUuid();

								User user3 = userService
										.getUserByPhoneNumber(phoneNum);
								String string = redisService.get(phoneNumber
										+ "_ADO");
								Date expriedTime = DateUtils.getExpriedTime();
								long time = (expriedTime.getTime() - System
										.currentTimeMillis()) / 1000;
								if (string == null) {
									redisService.set(phoneNumber + "_ADO", "0",
											time);
								} else {
									redisService.incrby(phoneNumber + "_ADO");
								}
								/*
								 * String string2 =
								 * redisService.get(phoneNum+"_"
								 * +phoneNumber+"_CA"); if(string2==null){
								 * redisService
								 * .set(phoneNum+"_"+phoneNumber+"_CA",
								 * BaseRes.SUCCESS_CODE, time); }else {
								 * redisService
								 * .incrby(phoneNum+"_"+phoneNumber+"_CA"); }
								 */

								if (status == 2) {
									// 修改问题的状态 采纳公开
									question2.setUuid(questionUuid);
									question2.setStatus(3);
									answerService
											.updateAndAddRewardUserAnswerQuestion(
													counselorUuid, answer,
													question2, money);
								} else if (status == 4) {
									// 修改问题的状态 采纳不公开
									question2.setUuid(questionUuid);
									question2.setStatus(4);
									answerService
											.updateAndAddRewardUserAnswerQuestion(
													counselorUuid, answer,
													question2, money);
								}
								/**
								 * 采纳加积分
								 */
								IntegralService.integral(phoneNum, "adop", 1);
								
								if (user3 != null) {
									String[] str = { String.valueOf(money),question.getContent()};
									smsSendService.sendNotify(appId, phone,
											Const.SCENE_ANSWER_ADOPT, str);
									pushService.pushAlias(PushType.MODEL_0,
											new String[] {questionUuid,String
													.valueOf(money),question.getContent()},
											phoneNumber, "1");
								}
								// 给没有被采纳的人 一个安慰奖
								List<User> users = answerUserService
										.getAnswerUserByQuestionId(questionUuid);
								for (User user4 : users) {
									double balance = user4.getBalance();
									// String realName = user4.getRealName();
									String phoneNumber2 = user4
											.getPhoneNumber();
									String phone2 = user4.getPhone();

									User user5 = new User();
									user5.setPhoneNumber(phoneNumber2);
									double comfortMoney = MoneyRandom
											.comfortMoney();
									user5.setBalance(balance + comfortMoney);
									answerService.updateAndAddRewardUser(user5,
											comfortMoney, questionUuid);
									String[] str = { String
											.valueOf(comfortMoney) };
									smsSendService.sendNotify(appId, phone2,
											Const.SCENE_ANSWER_ADOPTCOMFORT,
											str);
									String[] str1 = {questionUuid, String
											.valueOf(comfortMoney) };
									pushService.pushAlias(PushType.MODEL_1,
											str1, phoneNumber2, "1");
								}
							} else {
								// 已经采纳过答案
								updateAnswerStatusResponse
										.setCode(BaseRes.ERRORPARAM_CODE);
								updateAnswerStatusResponse
										.setDes("你已经采纳过答案,或者问题已经过期");
							}

						} else {
							// 数据格式错误
							updateAnswerStatusResponse
									.setCode(BaseRes.ERRORPARAM_CODE);
							updateAnswerStatusResponse.setDes("数据格式错误！");
						}
					} else if (status == 3) {
						answer.setStatus(3);
						answer.setUuid(answerUuid);
						answer.setReportTime(new Date());
						answerService.updateAnswer(answer);
						updateAnswerStatusResponse
								.setCode(BaseRes.SUCCESS_CODE);
					} else {
						// 状态错误
						updateAnswerStatusResponse
								.setCode(BaseRes.ERRORPARAM_CODE);
						updateAnswerStatusResponse.setDes("状态码错误！");
					}

				} else {
					// 你已经采纳过或者举报过
					updateAnswerStatusResponse.setCode(BaseRes.ERRORPARAM_CODE);
					updateAnswerStatusResponse.setDes("你已经采纳或者举报过此答案！");
				}
			} else {
				// 数据格式错误
				updateAnswerStatusResponse.setCode(BaseRes.ERRORPARAM_CODE);
				updateAnswerStatusResponse.setDes("数据格式错误！");
			}

			logger.info("返回："
					+ mapper.writeValueAsString(updateAnswerStatusResponse));

		} catch (Exception e) {

			e.printStackTrace();
			updateAnswerStatusResponse.setCode("0");
			updateAnswerStatusResponse.setDes("系统繁忙请稍后再试！");
		}
		return updateAnswerStatusResponse;
	}

	// 偷偷看详情

	@RequestMapping(value = "/secretly", method = RequestMethod.POST)
	@ResponseBody
	public Object secretlyDetail(HttpServletRequest request,
			@RequestBody AnswerUserRequest answerUserRequest) {

		AnswerUserResponse answerUserResponse = new AnswerUserResponse();
		try {
			logger.info("接收：" + mapper.writeValueAsString(answerUserRequest));

			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			String phoneNum = cookieUser.getPhoneNumber();
			String questionUuid = answerUserRequest.getQuestionUuid();
			Question question = questionService.getQuestionByUuid(questionUuid);
			if (question != null) {
				QuestionUserKey questionUserKey2 = new QuestionUserKey();
				questionUserKey2.setPhoneNumber(phoneNum);
				questionUserKey2.setQuestionUuid(questionUuid);
				QuestionUserKey questionUserKey = questionUserService
						.getQuestionUserKeys(questionUserKey2);
				String phoneNum2 = question.getPhoneNum();

				List<AnswerUser> answerUsers = answerUserService
						.getAnswerUserByQUid(questionUuid);
				Secretly secretly = new Secretly();
				if (answerUsers != null && answerUsers.size() > 0) {
					AnswerUser answerUser = answerUsers.get(0);

					if (answerUser != null) {
						String counselorDuty = answerUser.getCounselorDuty();
						StringBuilder stringBuilder = new StringBuilder();
						if (counselorDuty != null && !counselorDuty.equals("")) {
							String[] dutys = counselorDuty.split(",");
							for (String id : dutys) {
								if (id != null && !id.equals("")) {
									Duty duty = counselorDutyService
											.getDutyById(id);
									if (duty != null) {

										stringBuilder.append(duty.getDutyName()
												+ " ");
									}
								}
							}
							int i = stringBuilder.lastIndexOf(" ");
							stringBuilder.delete(i, i + 1);
							answerUser.setCounselorDuty(stringBuilder
									.toString());
						}
						secretly.setAnswerUuid(answerUser.getUuid());
						String phoneNumber = answerUser.getPhoneNumber();

						User user5 = userService
								.getUserByPhoneNumber(phoneNumber);

						if (questionUserKey != null
								|| phoneNum2.equals(phoneNum)) {
							answerUserResponse.setCode(BaseRes.SUCCESS_CODE);
							answerUserResponse.setAnswerUsers(answerUsers);

						} else {
							// 判断支付类型
							String payType = answerUserRequest.getPayType();
							if (payType == null || payType.equals("")) {
								answerUserResponse
										.setCode(BaseRes.ERRORPARAM_CODE);
								answerUserResponse.setDes("请支付");
								return answerUserResponse;
							}
							int money = answerUserRequest.getMoney();
							if (money != priceNum) {
								money = priceNum;
							}
							double totalMoney = secretlyService
									.getSumMoneyUser(phoneNum2, questionUuid);
							Integer addMoney = question.getAddMoney();
							Integer money2 = question.getMoney();
							if (addMoney != null) {
								money2 = money2 + addMoney;
							}

							double subMoney = MoneyRandom.getSubMoney(money);
							double subMoneyFifteen = MoneyRandom
									.getSubMoneyFifteen(money);
							User user = userService
									.getUserByPhoneNumber(phoneNum);// 偷看着
							User user4 = userService
									.getUserByPhoneNumber(phoneNum2);
							// String uuid =

							String uuid = UUIDGenerator.getUUID();
							String uuid2 = UUIDGenerator.getUUID();// 偷看者流水
							String uuid3 = UUIDGenerator.getUUID();// 提问题者流水表
																	// 70%
							String uuid4 = UUIDGenerator.getUUID();// 回答者流水表
																	// 15%
							String uuid5 = UUIDGenerator.getUUID();// 公司流水表

							UserDealRecord userDealRecord2 = new UserDealRecord();
							UserDealRecord userDealRecord3 = new UserDealRecord();
							UserDealRecord userDealRecord4 = new UserDealRecord();
							UserDealRecord userDealRecord5 = new UserDealRecord();

							userDealRecord2.setUuid(uuid2);
							userDealRecord2.setUserId(phoneNum);
							userDealRecord2.setBusinessNo(uuid);
							userDealRecord2
									.setAccountType(PayTypeUtil.ACCOUNTTYPE_PERSONAL);
							userDealRecord3.setUuid(uuid3);
							userDealRecord3.setUserId(question.getPhoneNum());

							userDealRecord3.setBusinessNo(uuid);
							userDealRecord3
									.setAccountType(PayTypeUtil.ACCOUNTTYPE_PERSONAL);
							userDealRecord4.setUuid(uuid4);
							userDealRecord4.setUserId(answerUser
									.getPhoneNumber());

							userDealRecord4.setBusinessNo(uuid);
							userDealRecord4
									.setAccountType(PayTypeUtil.ACCOUNTTYPE_PERSONAL);

							userDealRecord5.setUuid(uuid5);
							userDealRecord5
									.setUserId(PayTypeUtil.COMPANY_ACCPUNT);
							userDealRecord5.setBusinessNo(uuid);
							userDealRecord5
									.setAccountType(PayTypeUtil.ACCOUNTTYPE_BUSINESS);
							Date date = new Date();

							userDealRecord2.setCreateDate(date);
							userDealRecord2.setSum((double) money);
							userDealRecord2.setSum((double) money);
							userDealRecord2
									.setGoodsType(PayTypeUtil.GOODSTYPE_SECRETLY);
							userDealRecord2
									.setTradeType(PayTypeUtil.TRDETYPE_EXPENDITURE);

							userDealRecord3.setCreateDate(date);
							userDealRecord3.setSum(subMoney);
							userDealRecord3.setSum(subMoney);
							userDealRecord3
									.setGoodsType(PayTypeUtil.GOODSTYPE_SECRETLY);
							userDealRecord3
									.setTradeType(PayTypeUtil.TRDETYPE_INCOME);

							userDealRecord4.setCreateDate(date);
							userDealRecord4.setSum(subMoneyFifteen);
							userDealRecord4.setSum(subMoneyFifteen);
							userDealRecord4
									.setGoodsType(PayTypeUtil.GOODSTYPE_SECRETLY);
							userDealRecord4
									.setTradeType(PayTypeUtil.TRDETYPE_INCOME);

							userDealRecord5.setCreateDate(date);
							userDealRecord5.setSum(subMoneyFifteen);
							userDealRecord5.setSum(subMoneyFifteen);
							userDealRecord5
									.setGoodsType(PayTypeUtil.GOODSTYPE_SECRETLY);
							userDealRecord5
									.setTradeType(PayTypeUtil.TRDETYPE_INCOME);

							secretly.setUuid(uuid);
							secretly.setMentionPhoneNum(phoneNum2);
							secretly.setPayStatus(PayCommonUtil.PAYSUCCESS_STATUS);
							secretly.setPeepPhoneNum(phoneNum);
							secretly.setQuestionUuid(questionUuid);
							secretly.setSecretlyDate(date);
							secretly.setSecretlyMoney(subMoney);

							if (payType.equals("balance")
									|| payType.equals("personal")) {

								if (user != null && user4 != null
										&& user5 != null) {
									User user2 = new User();// 偷看着
									User user3 = new User();// 公布者
									User user6 = new User();// 回答者
									if (payType.equals("balance")) {
										Double balance = user.getBalance();
										if (balance >= money) {
											user2.setBalance(balance - money);
											userDealRecord2
													.setPayType(PayTypeUtil.PAYTYPE_BALANCE);
											userDealRecord3
													.setPayType(PayTypeUtil.PAYTYPE_BALANCE);
											userDealRecord4
													.setPayType(PayTypeUtil.PAYTYPE_BALANCE);
											userDealRecord5
													.setPayType(PayTypeUtil.PAYTYPE_BALANCE);
											secretly.setPayType(PayTypeUtil.PAYTYPE_BALANCE);
										} else {
											// 余额不足
											answerUserResponse.setCode("4");
											answerUserResponse
													.setDes("余额不足,请充值");
											return answerUserResponse;
										}
									}

									if (payType.equals("personal")) {
										answerUserResponse
												.setCode(BaseRes.ERRORPARAM_CODE);
										answerUserResponse.setDes("请更新版本");
										return answerUserResponse;
										/*
										 * Double vipBalance =
										 * user.getVipBalance();
										 * if(vipBalance>=money){
										 * user2.setVipBalance
										 * (vipBalance-money);
										 * userDealRecord2.setPayType
										 * (PayTypeUtil.PAYTYPE_VIPBALANCE);
										 * userDealRecord3
										 * .setPayType(PayTypeUtil
										 * .PAYTYPE_VIPBALANCE);
										 * userDealRecord4.
										 * setPayType(PayTypeUtil
										 * .PAYTYPE_VIPBALANCE);
										 * userDealRecord5.
										 * setPayType(PayTypeUtil
										 * .PAYTYPE_VIPBALANCE);
										 * secretly.setPayType
										 * (PayTypeUtil.PAYTYPE_VIPBALANCE);
										 * }else {
										 * answerUserResponse.setCode("4");
										 * answerUserResponse
										 * .setDes("个人会员卡余额不足,请充值"); return
										 * answerUserResponse; }
										 */
									}
									user3.setPhoneNumber(phoneNum2);
									user3.setBalance(user4.getBalance()
											+ subMoney);

									user2.setPhoneNumber(phoneNum);

									user6.setPhoneNumber(phoneNumber);
									user6.setBalance(user5.getBalance()
											+ subMoneyFifteen);

									Date date2 = new Date();

									userDealRecord2.setPaySucTime(date2);

									userDealRecord2
											.setStatus(PayCommonUtil.PAYSUCCESS_STATUS);

									userDealRecord3.setPaySucTime(date2);

									userDealRecord3
											.setStatus(PayCommonUtil.PAYSUCCESS_STATUS);

									userDealRecord4.setPaySucTime(date2);

									userDealRecord4
											.setStatus(PayCommonUtil.PAYSUCCESS_STATUS);

									userDealRecord5.setPaySucTime(date2);

									userDealRecord5
											.setStatus(PayCommonUtil.PAYSUCCESS_STATUS);

									List<UserDealRecord> arrayList = new ArrayList<UserDealRecord>();
									arrayList.add(userDealRecord2);
									if (totalMoney <= (money2 * 2)) {
										arrayList.add(userDealRecord3);

										arrayList.add(userDealRecord4);

										arrayList.add(userDealRecord5);
										// 把钱给用户
										userService
												.updateUserAndUserQuestionUserKey(
														user2, user3, user6,
														questionUserKey,
														questionUserKey2,
														secretly, arrayList);
									} else {
										userDealRecord5.setSum((double) money);

										arrayList.add(userDealRecord5);
										// 把钱给用户
										userService
												.updateUserAndUserQuestionUserKey(
														user2, null, null,
														questionUserKey,
														questionUserKey2,
														secretly, arrayList);

									}

									answerUserResponse
											.setCode(BaseRes.SUCCESS_CODE);

									answerUserResponse
											.setAnswerUsers(answerUsers);

									// 返回详情数据
								} else {
									// return
								}

							} else if (payType.equals("VipBalance")) {
								answerUserResponse
										.setCode(BaseRes.ERRORPARAM_CODE);
								answerUserResponse.setDes("此功能只支持最新版本");
								return answerUserResponse;
							} else if (payType.equals("business")) {

								answerUserResponse
										.setCode(BaseRes.ERRORPARAM_CODE);
								answerUserResponse.setDes("请更新版本");
								return answerUserResponse;

								/*
								 * if(user!=null){ Integer companyRole =
								 * user.getCompanyRole(); if(companyRole!=0){
								 * userDealRecord2
								 * .setUserId(user.getCompanyUuid()); }else {
								 * answerUserResponse
								 * .setCode(BaseRes.ERRORPARAM_CODE);
								 * answerUserResponse
								 * .setDes("你不是企业用户，不能选择企业会员卡"); return
								 * answerUserResponse; } }
								 * 
								 * List<UserDealRecord> arrayList = new
								 * ArrayList<UserDealRecord>(); int i=3;
								 * arrayList.add(userDealRecord2);
								 * 
								 * if(totalMoney<=(money2*2)){
								 * 
								 * arrayList.add(userDealRecord3);
								 * 
								 * arrayList.add(userDealRecord4);
								 * 
								 * arrayList.add(userDealRecord5);
								 * 
								 * i = payVipBanlanceService.
								 * updateUserAndCompanyQuestionUserKey(user,
								 * user4,
								 * user5,questionUserKey,questionUserKey2,money,
								 * secretly,arrayList); }else {
								 * userDealRecord5.setSum((double)money);
								 * 
								 * arrayList.add(userDealRecord5);
								 * 
								 * i = payVipBanlanceService.
								 * updateUserAndCompanyQuestionUserKey(user,
								 * null,
								 * null,questionUserKey,questionUserKey2,money,
								 * secretly,arrayList);
								 * 
								 * } if (i == 1 || i == 2) {
								 * answerUserResponse.setAnswerUsers
								 * (answerUsers); answerUserResponse.setCode(
								 * BaseRes.SUCCESS_CODE); return
								 * answerUserResponse; } else if (i == 3) {
								 * answerUserResponse
								 * .setCode(BaseRes.ERRORPARAM_CODE);
								 * answerUserResponse.setDes("数据格式错误"); return
								 * answerUserResponse; } else if (i == 4) {
								 * answerUserResponse.setCode("4");
								 * answerUserResponse.setDes("企业会员卡余额不足，请充值");
								 * return answerUserResponse; } else if (i == 0)
								 * { answerUserResponse.setCode("0");
								 * answerUserResponse.setDes("系统繁忙!"); return
								 * answerUserResponse; }
								 */

							} else if (payType.equals("weixin")) {
								secretly.setPayStatus(PayCommonUtil.PAYPENDING_STATUS);
								secretly.setPayType(PayTypeUtil.PAYTYPE_WEIXIN);
								secretlyService.addSecretly(secretly);
								int source = answerUserRequest.getSource();
								if (source == 1) {
									String code = answerUserRequest.getCode();
									WxJsPayReq req = new WxJsPayReq();
									req.setCode(code);
									req.setPhone(phoneNum);
									req.setUnitPrice((double) money);
									req.setProductName("偷偷看");
									req.setProductType(Const.TTK);
									req.setProductId(uuid);
									WxjsPayRes jssdPayRes = (WxjsPayRes) weiXinPayService
											.jSSDKPayInfo(req, request);
									return jssdPayRes;
								} else {
									WxAppPayReq wxAppPayReq = new WxAppPayReq();
									double price = money;
									wxAppPayReq.setUnitPrice(price);
									wxAppPayReq.setProductName("偷偷看");
									wxAppPayReq.setPhone(phoneNum);
									wxAppPayReq.setProductType(producttypeTtk);
									wxAppPayReq.setProductId(uuid);
									WxAppPayRes appPay = (WxAppPayRes) weiXinPayService
											.appPay(wxAppPayReq, request);
									return appPay;
								}
							} else {
								// 请选择支付方式
								answerUserResponse.setCode("4");
								answerUserResponse.setDes("请选择支付方式");
							}

						}
					} else {
						// 数据格式错误
						answerUserResponse.setCode(BaseRes.ERRORPARAM_CODE);
						answerUserResponse.setDes("数据格式错误");
					}

				} else {
					// 数据格式错误
					answerUserResponse.setCode(BaseRes.ERRORPARAM_CODE);
					answerUserResponse.setDes("数据格式错误");
				}

			} else {
				// 数据格式错误
				answerUserResponse.setCode(BaseRes.ERRORPARAM_CODE);
				answerUserResponse.setDes("数据格式错误");
			}

			logger.info("返回：" + mapper.writeValueAsString(answerUserResponse));

		} catch (Exception e) {

			e.printStackTrace();
			answerUserResponse.setCode("0");
			answerUserResponse.setDes("系统繁忙!!");
		}

		return answerUserResponse;
	}

	// 赞成与不赞成
	@RequestMapping(value = "/proveAndpose", method = RequestMethod.POST)
	@ResponseBody
	public Object proveAndPose(HttpServletRequest request,
			@RequestBody ApproveOpposeRequest approveOpposeRequest) {
		AddAdmireResponse proveAndPoseResponse = new AddAdmireResponse();
		try {
			logger.info("接收：" + mapper.writeValueAsString(approveOpposeRequest));

			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			String phoneNum = cookieUser.getPhoneNumber();
			String answerUuid = approveOpposeRequest.getAnswerUuid();
			int status = approveOpposeRequest.getStatus();// 1 赞成 2
															// 不赞成
			Answer answer = answerService.getAnswerByUuid(answerUuid);
			if (answer != null) {
				if (status == 1 || status == 2) {
					PraiseExample praiseExample = new PraiseExample();
					Criteria createCriteria = praiseExample.createCriteria();
					createCriteria.andUserIdEqualTo(phoneNum);
					createCriteria.andProductIdEqualTo(answerUuid);
					createCriteria.andTypeEqualTo("0");// 0 答案的点赞
					List<Praise> list = praiseService.getPraises(praiseExample);

					Answer answer2 = new Answer();
					answer2.setUuid(answerUuid);
					if (list == null || list.size() < 1) {
						Praise praise = new Praise();
						String uuid = IdGen.uuid();
						praise.setUuid(uuid);
						praise.setProductId(answerUuid);
						praise.setType("0");
						praise.setUserId(phoneNum);

						if (status == 1) {
							answer2.setApproveNum(1);
							praise.setPraiseNum(1);
						} else {
							answer2.setOpposeNum(1);
							praise.setTreadNum(1);
						}
						praiseService.addPraise(praise);

					} else {
						Praise praise = list.get(0);
						Integer praiseNum = praise.getPraiseNum();
						praiseNum = praiseNum == null ? praiseNum = 0
								: praiseNum;
						Integer treadNum = praise.getTreadNum();
						treadNum = treadNum == null ? treadNum = 0 : treadNum;
						if (status == 1) {
							if (praiseNum > 0) {
								// 已点赞
								proveAndPoseResponse.setCode(BaseRes.FAIL_CODE);
								proveAndPoseResponse.setDes("已点赞！");
								return proveAndPoseResponse;

							} else {
								praise.setPraiseNum(1);
								answer2.setApproveNum(1);
							}

						} else {
							if (treadNum > 0) {
								// 已踩
								proveAndPoseResponse.setCode(BaseRes.FAIL_CODE);
								proveAndPoseResponse.setDes("已经踩过！");
								return proveAndPoseResponse;
							} else {
								answer2.setOpposeNum(1);
								praise.setTreadNum(1);
							}

						}

						praiseService.updatePraise(praise);
					}
					answerUserService.updateAnswerApproveNum(answer2);
					proveAndPoseResponse.setCode(BaseRes.SUCCESS_CODE);
				} else {
					// 数据格式错误
					proveAndPoseResponse.setCode(BaseRes.ERRORPARAM_CODE);
					proveAndPoseResponse.setDes("数据格式错误");
				}
			} else {
				// 数据格式错误
				proveAndPoseResponse.setCode(BaseRes.ERRORPARAM_CODE);
				proveAndPoseResponse.setDes("数据格式错误");
			}

			logger.info("返回：" + mapper.writeValueAsString(proveAndPoseResponse));

		} catch (Exception e) {

			e.printStackTrace();
			proveAndPoseResponse.setCode("0");
			proveAndPoseResponse.setDes("系统繁忙");
		}
		return proveAndPoseResponse;
	}

	// 抢答接口
	@RequestMapping(value = "/grabAnswer", method = RequestMethod.POST)
	@ResponseBody
	public Object grabAnswer(HttpServletRequest request,
			@RequestBody PageRequest pageRequest) {
		AddAdmireResponse proveAndPoseResponse = new AddAdmireResponse();
		try {
			logger.info("接收：" + mapper.writeValueAsString(pageRequest));

			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			String phoneNum = cookieUser.getPhoneNumber();
			String ipAddress = NetworkUtil.getIpAddress(request);
			User user = userService.getUserByPhoneNumber(phoneNum);
			if (user != null) {
				String realName = user.getRealName();
				// String province = user.getProvince();
				String string2 = redisService.get(phoneNum + "_ADO");
				boolean answerWait = answerUserService.isAnswerWait(phoneNum);
				if (answerWait) {
					proveAndPoseResponse.setCode(BaseRes.ERRORPARAM_CODE);
					proveAndPoseResponse.setDes("您还有未提交的答案！");
					return proveAndPoseResponse;
				}
				if (string2 != null && Integer.valueOf(string2) >= 3) {
					proveAndPoseResponse.setCode(BaseRes.ERRORPARAM_CODE);
					proveAndPoseResponse
							.setDes("您太厉害了今天已经被采纳超过3次，给其他咨询师留点机会吧！");
					return proveAndPoseResponse;
				}
				String uuid = pageRequest.getUuid();
				String keyLimit=phoneNum+"_grablimit_"+uuid;
				String limit = redisService.get(keyLimit);
				if (limit==null) {
					redisService.set(keyLimit, "1", 3);
				}else {
					proveAndPoseResponse
					.setCode(BaseRes.FAIL_CODE);
					proveAndPoseResponse
					.setDes("请稍后再试！");
					return proveAndPoseResponse;
				}
				
				
				
				if (realName != null && !realName.equals("")) {
					Integer role = user.getRole();
					if (role == 2) {
						
						Answer answer2 = answerUserService.getAnswerStatus(
								uuid, phoneNum);
						if (answer2 != null) {
							// 你一回答过
							proveAndPoseResponse
									.setCode(BaseRes.ERRORPARAM_CODE);
							proveAndPoseResponse.setDes("你已经抢到！");
						} else {
							if (uuid != null && !uuid.equals("")) {
								Question question2 = questionService
										.getQuestionByUuid(uuid);

								if (question2 != null) {
									String quIp = question2.getQuIp();
									List<String> whithList = Arrays
											.asList(Const.IPWHITE);
									if (!whithList.contains(quIp)) {
										if (quIp != null
												&& ipAddress.equals(quIp)) {
											proveAndPoseResponse
													.setCode(BaseRes.ERRORPARAM_CODE);
											proveAndPoseResponse
													.setDes("您不能抢答同一ip下的问题");
											return proveAndPoseResponse;
										}
									}

									String phoneNum2 = question2.getPhoneNum();
									Integer status = question2.getStatus();
                                    if (status!=null&&status!=QuestionStatus.QU_STATUS_CHUSHI.getCode()&&status!=QuestionStatus.QU_STATUS_ANSWER.getCode()) {
                                        proveAndPoseResponse
                                        .setCode(BaseRes.ERRORPARAM_CODE);
                                        proveAndPoseResponse.setDes("你来迟了一步");
                                        return proveAndPoseResponse;
                                    }
                                    Date endDate = question2.getEndDate();
                                    if (endDate.before(new Date())) {
                                        proveAndPoseResponse
                                        .setCode(BaseRes.ERRORPARAM_CODE);
                                        proveAndPoseResponse.setDes("你来迟了一步");
                                        return proveAndPoseResponse;
                                    }

									// String area =
									// question2.getArea();
									Integer answerNum = question2
											.getAnswerNum();
									if (answerNum != null && answerNum == 2) {
										proveAndPoseResponse
												.setCode(BaseRes.ERRORPARAM_CODE);
										proveAndPoseResponse.setDes("你来迟了一步");
										return proveAndPoseResponse;
									}
									if (phoneNum.equals(phoneNum2)) {
										proveAndPoseResponse
												.setCode(BaseRes.ERRORPARAM_CODE);
										proveAndPoseResponse
												.setDes("你不能抢答自己的问题");
										return proveAndPoseResponse;
									}
									/*
									 * if(area!=null&&!area.equals("全国" )
									 * &&!area.equals("")&&province !=
									 * null&&!province.equals("")){
									 * if(!area.equals(province)){
									 * proveAndPoseResponse .setCode(BaseRes
									 * .ERRORPARAM_CODE); proveAndPoseResponse
									 * .setDes("你不能抢答此地区的问题"); return
									 * proveAndPoseResponse; } }
									 */
									String string = redisService.get(uuid
											+ "_num");
									Answer answer = new Answer();
									answer.setPhoneNumber(phoneNum);
									answer.setQuestionUuid(uuid);
									answer.setStatus(0);
									answer.setGrabDate(new Date());
									String answerUuid = UUIDGenerator.getUUID();
									answer.setUuid(answerUuid);
									if (string != null && !string.equals("")) {
										Integer i = Integer.valueOf(string);
										if (i < 2) {

											answerUserService
													.addAnswerAndQuestion(
															answer, null);

											if ((i + 1) == 2) {
												Question question = new Question();
												question.setUuid(uuid);
												question.setAnswerNum(2);
												answerUserService
														.addAnswerAndQuestion(
																null, question);
											}
											redisService.incrby(uuid + "_num");
											proveAndPoseResponse
													.setCode(BaseRes.SUCCESS_CODE);
											proveAndPoseResponse.setDes("你抢到了");
										} else {
											// 已抢答玩
											proveAndPoseResponse.setCode("4");

											proveAndPoseResponse
													.setDes("你来迟了一步");
											return proveAndPoseResponse;
										}

									} else {
										// 第一次
										redisService.set(uuid + "_num", "1", 0);
										answerUserService.addAnswerAndQuestion(
												answer, null);
										proveAndPoseResponse
												.setCode(BaseRes.SUCCESS_CODE);
										proveAndPoseResponse.setDes("你抢到了");
									}
									/**
									 * 记录一天之内抢答同一个人问题的次数
									 */
									Date expriedTime = DateUtils
											.getExpriedTime();
									long time = (expriedTime.getTime() - System
											.currentTimeMillis()) / 1000;
									// phoneNum2 提问者的id phoneNum
									// 抢答着id
									String ca = redisService.get(phoneNum2
											+ "_" + phoneNum + "_CA");
									if (ca == null) {
										redisService.set(phoneNum2 + "_"
												+ phoneNum + "_CA", "1", time);
									} else {
										redisService.incrby(phoneNum2 + "_"
												+ phoneNum + "_CA");
									}

								} else {
									proveAndPoseResponse
											.setCode(BaseRes.ERRORPARAM_CODE);
									proveAndPoseResponse.setDes("uuid错误！");
								}

							} else {
								// 数据格式错误
								proveAndPoseResponse
										.setCode(BaseRes.ERRORPARAM_CODE);
								proveAndPoseResponse.setDes("问题异常");
							}
						}

					} else {
						// 你不是咨询师
						proveAndPoseResponse.setCode("4");
						proveAndPoseResponse.setDes("你不是咨询师！");
					}
				} else {
					// 未完善信息
					proveAndPoseResponse.setCode("4");
					proveAndPoseResponse.setDes("未完善信息");
				}
			} else {
				// 重新登录
				proveAndPoseResponse.setCode(BaseRes.RELOGIN_CODE);
				proveAndPoseResponse.setDes("重新登录");
			}

			logger.info("返回：" + mapper.writeValueAsString(proveAndPoseResponse));

		} catch (Exception e) {

			e.printStackTrace();
			proveAndPoseResponse.setCode("0");
			proveAndPoseResponse.setDes("系统繁忙");
		}
		return proveAndPoseResponse;
	}

	// 是否有没有提交的抢答

	@RequestMapping(value = "/isAnswer", method = RequestMethod.POST)
	@ResponseBody
	public Object isAnswer(HttpServletRequest request) {
		Map<String, Object> res=new HashMap<String, Object>();
		try {
			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			String phoneNum = cookieUser.getPhoneNumber();
			String cookieId = request.getHeader("cookieId");
			if (cookieId != null) {
				if (cookieUser != null) {
					if (phoneNum != null) {
						List<Answer> answerByPhone = answerUserService
								.getAnswerByPhone(phoneNum);
						if (answerByPhone != null) {
							for (Answer answer : answerByPhone) {
								if (answer != null) {
									Integer status = answer.getStatus();
									if (status == 0) {
										String questionUuid = answer
												.getQuestionUuid();
										QuestionUserEx questionExByUuid = questionExService
												.getQuestionExByUuid(questionUuid);
										String counselorDuty = questionExByUuid
												.getCounselorDuty();
										if (counselorDuty != null
												&& !counselorDuty.equals("")) {
											String dutyName = counselorDutyService.getCounselorDutyName(counselorDuty);
											questionExByUuid.setCounselorDuty(dutyName);
										}
										res.put("code", "4");
										res.put("des", "您有未回答的问题，请前去回答");
										res.put("question",questionExByUuid);
										return res;
									}
								}

							}
						}
					}
				}

			}
			res.put("code", BaseRes.SUCCESS_CODE);

			logger.info("返回：" + mapper.writeValueAsString(res));

		} catch (Exception e) {
			e.printStackTrace();
			res.put("code", BaseRes.FAIL_CODE);
			res.put("des", BaseRes.FAIL_DES);
		}
		return res;
	}

	// 打分

	@RequestMapping(value = "/score", method = RequestMethod.POST)
	@ResponseBody
	public Object scoreeValuate(HttpServletRequest request,
			@RequestBody ScoreRequest scoreRequest) {
		HashMap<String, String> map = new HashMap<String, String>();

		try {
			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			String phoneNum = cookieUser.getPhoneNumber();
			User user = userService.getUserByPhoneNumber(phoneNum);
			if (user != null) {
				int score = scoreRequest.getScore();
				String appraisal = scoreRequest.getAppraisal();

				if (score > 5) {
					score = 5;
				}
				if (score == 0) {
					score = 1;
				}
				String uuid = scoreRequest.getUuid();
				if (uuid == null || uuid.equals("")) {
					map.put("code", BaseRes.ERRORPARAM_CODE);
					map.put("des", "答案的uuid为空");
					return map;
				}
				Answer answer = answerService.getAnswerByUuid(uuid);
				if (answer != null) {
					String phoneNumber = answer.getPhoneNumber();
					Counselor counselor = userService
							.getCounselorByPhoneNumber(phoneNumber);

					if (counselor != null) {
						Integer grabScore = counselor.getGrabScore();
						counselor.setGrabScore(grabScore + score - 5);

					}
					Answer answer2 = new Answer();
					answer2.setUuid(uuid);
					answer2.setScore(score);
					answer2.setAppraisal(appraisal);
					answerService.updateAnswerAndCounselor(answer2, counselor);
					map.put("code", BaseRes.SUCCESS_CODE);
					map.put("des", "提交成功");
					logger.info("返回：" + mapper.writeValueAsString(map));
					return map;
				} else {
					map.put("code", BaseRes.ERRORPARAM_CODE);
					map.put("des", "答案的uuid错误");
					return map;
				}
			} else {

				// 重新登录
				map.put("code", BaseRes.RELOGIN_CODE);
				map.put("des", "重新登录");
				return map;
			}

		} catch (Exception e) {

			e.printStackTrace();
			map.put("code", "0");
			map.put("des", "网络繁忙");
		}
		return map;
	}
	
	

	@RequestMapping(value = "/grab/details/question", method = RequestMethod.POST)
	@ResponseBody
	public Object grabQestionDeatils(HttpServletRequest request,
			@RequestBody(required=false) PageRequest req) {
		BaseRes<QuestionUserEx> res = new BaseRes<QuestionUserEx>();
		try {
			if (req==null) {
				res.setCode(BaseRes.ERRORPARAM_CODE);
				res.setDes(BaseRes.ERRORPARAM_DES);
				return res;
			}
			String uuid = req.getUuid();
			if (StringUtils.isBlank(uuid)) {
				res.setCode(BaseRes.ERRORPARAM_CODE);
				res.setDes(BaseRes.ERRORPARAM_DES);
				return res;
			}
			
			QuestionUserEx userEx = questionExService.getQuestionExByUuid(uuid);
			if (userEx==null) {
				res.setCode(BaseRes.ERRORPARAM_CODE);
				res.setDes(BaseRes.ERRORPARAM_DES);
				return res;
			}
			CookieUser cookieUser = (CookieUser) request
					.getAttribute("cookieUser");
			int role = cookieUser.getRole();
			if (role!=Const.USER_ROLE_2) {
				res.setCode(BaseRes.FAIL_CODE);
				res.setDes("只有咨询师可以抢答！");
				return res;
			}
			res.setData(userEx);
			res.setCode(BaseRes.SUCCESS_CODE);
			res.setDes(BaseRes.SUCCESS_DES);
			return res;
		} catch (Exception e) {

			e.printStackTrace();
			res.setCode(BaseRes.FAIL_CODE);
			res.setDes(BaseRes.FAIL_DES);
			return res;
		}
	}
}
